<template>
	<div style="height: 100%;">

		<div class="displayFlexBet point mb10">
			<div></div>
			<el-button
				@click="visible1 = true,form = {},parameter= {list: []},productList= [],materialList= [],pollutionList=[]"
				icon="el-icon-plus" type="primary" size="mini">新增</el-button>
		</div>

		<div v-if="dataList && dataList[0]" style="height: calc(100% - 40px);overflow-y: auto;" v-infinite-scroll="load">
			<div v-for="(secondData,index3) in dataList" :key="index3">
				<div v-for="(item,index) in secondData" :key="index" @click="editThis(item)"
					style="background: #fff;border-radius: 16px;padding: 20px;margin-bottom: 20px;">

					<div style="font-size: 16px;margin-bottom: 10px;">
						<span>{{item.equipmentName}}</span>
						<span style="font-size: 12px;">（{{item.equipmentNo}}）</span>
						<span style="font-size: 12px;">（{{item.equipmentProductivity}}{{item.unitValue}}/天）</span>
					</div>
					<el-row :gutter="20">
						<el-col :span="8">
							<div class="displayFlex" style="margin-bottom: 10px;">
								<div style="background: #f5f5f5;width: 28px;height: 28px;border-radius: 6px;">
									<img src="@/assets/sIcon1.png" style="width: 20px;height: 20px;margin: 4px;" />
								</div>
								<div style="margin-left: 10px;">主要规格参数指标</div>
							</div>

							<el-table :data="item.parameterList" border size="mini" stripe
								style="width: 100%;height: 215px;overflow-y: auto;border-radius: 8px;">
								<el-table-column type="index" width="50">
								</el-table-column>
								<el-table-column prop="parameterName" label="规格参数">
								</el-table-column>
								<el-table-column prop="designValueStr" label="数值" width="180">
								</el-table-column>
								<el-table-column prop="unitCode" label="单位" width="80">
								</el-table-column>
							</el-table>
						</el-col>

						<el-col :span="8">

							<div class="displayFlex" style="margin-bottom: 10px;">
								<div style="background: #f5f5f5;width: 28px;height: 28px;border-radius: 6px;">
									<img src="@/assets/sIcon3.png" style="width: 20px;height: 20px;margin: 4px;" />
								</div>
								<div style="margin-left: 10px;">产品信息</div>
							</div>

							<el-table :data="item.productList" border size="mini" stripe
								style="width: 100%;height: 215px;overflow-y: auto;border-radius: 8px;">
								<el-table-column type="index" width="50">
								</el-table-column>
								<el-table-column prop="productName" label="产品">
								</el-table-column>
								<el-table-column prop="relationList" label="原辅料" width="180">
									<template slot-scope="scope">
										<div v-if="scope.row.relationList && scope.row.relationList.length > 0">
											<div v-for="(item,index) in scope.row.relationList" :key="index">
												<span>{{item.materialName}}</span>
												<span style="margin-left: 10px;">{{item.ratio}}{{item.unitValue}}</span>
											</div>
										</div>
									</template>
								</el-table-column>
							</el-table>
						</el-col>

						<el-col :span="8">
							<div class="displayFlex" style="margin-bottom: 10px;">
								<div style="background: #f5f5f5;width: 28px;height: 28px;border-radius: 6px;">
									<img src="@/assets/sIcon4.png" style="width: 20px;height: 20px;margin: 4px;" />
								</div>
								<div style="margin-left: 10px;">
									<span>原辅料</span>
									<span style="font-size: 10px;">({{item.materialList.length}})</span>
								</div>
							</div>
							<el-table :data="item.materialList" border size="mini" stripe
								style="width: 100%;height: 215px;overflow-y: auto;border-radius: 8px;">
								<el-table-column type="index" width="50">
								</el-table-column>
								<el-table-column prop="materialName" label="原辅料">
								</el-table-column>
								<el-table-column prop="unitValue" label="单位" width="80">
								</el-table-column>
								<el-table-column prop="busiStatus" label="状态" align="center">
									<template slot-scope="scope">
										<el-tag v-if="scope.row.busiStatus !='NOT_USE'" type="success" size="mini">启用</el-tag>
										<el-tag v-else type="danger" size="mini">停用</el-tag>
									</template>
								</el-table-column>
							</el-table>
						</el-col>

					</el-row>
				</div>
			</div>
		</div>

		<div v-else style="background: #fff;border-radius: 16px;">
			<el-empty description="暂无内容"></el-empty>
		</div>


		<el-dialog v-if="visible1" :visible.sync="visible1" top="2%" title="生产设施信息" width="80%"
			@close="getDataList(false)" :zIndex="99">
			<el-tabs :value="activeName" @tab-click="handleClick">
				<el-tab-pane label="产线" name="one">
					<el-form ref="form" :model="form" :rules="formRules" label-width="140px">
						<el-form-item label="产线名称" prop="equipmentName">
							<el-input v-model="form.equipmentName"></el-input>
						</el-form-item>
						<el-form-item label="产线编号" prop="equipmentNo">
							<el-input v-model="form.equipmentNo"></el-input>
						</el-form-item>

						<el-form-item label="生产设计能力" prop="equipmentProductivity">
							<el-input v-model="form.equipmentProductivity"></el-input>
						</el-form-item>
						<el-form-item label="生产设计能力单位" prop="unitCode">
							<el-select v-model="form.unitCode" style="width: 250px;">
								<el-option :label="item.value" :value="item.code" v-for="(item,index) in unitList">
								</el-option>
							</el-select>
						</el-form-item>

						<div style="text-align: center;">
							<el-button v-if="form.isEdit" type="danger" @click="deleteProductionEquipmentBase">
								删除
							</el-button>
							<el-button type="primary" @click="saveInfo(1)">保存</el-button>
							<el-button type="primary" @click="saveInfo(2)">保存并继续</el-button>
						</div>
					</el-form>
				</el-tab-pane>

				<el-tab-pane label="产品及原辅料" name="three">
					<el-button style="height: 32px;line-height: 30px; padding-top: 0; padding-bottom: 0;margin-bottom: 10px;"
						size="small" @click="addProduction()" type="primary">
						+ 添加产品信息
					</el-button>
					<template v-if="productList.length > 0">
						<el-table :data="productList" border size="mini" stripe
							style="width: 100%;height: 100%;overflow-y: auto;border-radius: 8px;">
							<el-table-column type="index" width="50">
							</el-table-column>
							<el-table-column prop="productName" label="产品">
							</el-table-column>
							<el-table-column prop="unitValue" label="单位">
							</el-table-column>
							<el-table-column prop="rawMaterialList" label="原料">
								<template slot-scope="scope">
									<div v-if="scope.row.rawMaterialList && scope.row.rawMaterialList.length > 0">
										<div v-for="(item,index) in scope.row.rawMaterialList" :key="index">
											<span>{{item.materialName}}</span>
											<span style="margin-left: 10px;">{{item.ratio}}{{item.unitValue}}</span>
										</div>
									</div>
								</template>
							</el-table-column>
							<el-table-column prop="assistMaterialList" label="辅料">
								<template slot-scope="scope">
									<div v-if="scope.row.assistMaterialList && scope.row.assistMaterialList.length > 0">
										<div v-for="(item,index) in scope.row.assistMaterialList" :key="index">
											<span>{{item.materialName}}</span>
											<span style="margin-left: 10px;">{{item.ratio}}{{item.unitValue}}</span>
										</div>
									</div>
								</template>
							</el-table-column>
							<el-table-column label="操作" width="100" align="center">
								<template slot-scope="scope">
									<el-button type="text" size="small" @click="deleteProduction(scope.row)"
										style="color: #F56C6C;">
										删除
									</el-button>
									<el-button type="text" size="small" @click="addProduction(scope.row)">编辑</el-button>
								</template>
							</el-table-column>
						</el-table>
					</template>
				</el-tab-pane>


				<el-tab-pane label="产生污染物" name="four">
					<el-button style="height: 32px;line-height: 30px; padding-top: 0; padding-bottom: 0;margin-bottom: 10px;"
						size="small" @click="addMaterial()" type="primary">
						+ 添加污染物
					</el-button>

					<template v-if="pollutionList.length > 0">
						<el-table :data="pollutionList" border size="mini" stripe
							style="width: 100%;height: 100%;overflow-y: auto;border-radius: 8px;">
							<el-table-column type="index" width="50">
							</el-table-column>
							<el-table-column prop="pollutionName" label="污染物">

							</el-table-column>
							<el-table-column prop="pollutionUnitCode" label="计量单位">
							</el-table-column>
							<el-table-column prop="pollutionType" label="污染物类别">
								<template slot-scope="scope">
									<span v-if="scope.row.pollutionType == 'GAS_POLLUTION'">废气</span>
									<span v-else>废水</span>
								</template>
							</el-table-column>

							<el-table-column prop="materialName" label="产生来源">
							</el-table-column>
							<el-table-column prop="qty" label="单位原辅材料产污量">
								<template slot-scope="scope">
									<span>{{scope.row.qty}}{{scope.row.materialUnitValue}}</span>
								</template>
							</el-table-column>
							<el-table-column label="操作" width="100" align="center">
								<template slot-scope="scope">
									<el-button type="text" size="small" @click="deleteProduction(scope.row)"
										style="color: #F56C6C;">
										删除
									</el-button>
									<el-button type="text" size="small" @click="addProduction(scope.row)">编辑</el-button>
								</template>
							</el-table-column>
						</el-table>
					</template>
				</el-tab-pane>

				<el-tab-pane label="生产设备" name="five">
					<productionEquipment :equipmentId="form.id"></productionEquipment>
				</el-tab-pane>

				<el-tab-pane label="关联排口" name="six">
					<div>
						<div class="mb10">废气</div>
						<el-checkbox-group v-model="outletParams.gasOutletIdList">
							<div class="displayFlex" style="flex-wrap:wrap">
								<div v-for="(item,index) in gasOutletList" class="mr20">
									<el-checkbox :label="item.outletId">{{item.outletName}}</el-checkbox>
								</div>
							</div>
						</el-checkbox-group>

						<div class="mb10 mt20">废水</div>
						<el-checkbox-group v-model="outletParams.waterOutletIdList">
							<div class="displayFlex" style="flex-wrap:wrap">
								<div v-for="(item,index) in waterOutletList" class="mr20">
									<el-checkbox :label="item.outletId">{{item.outletName}}</el-checkbox>
								</div>
							</div>
						</el-checkbox-group>

						<div class="textCenter mt20">
							<el-button type="primary" @click="saveOutLetParams">保存</el-button>
						</div>
					</div>
				</el-tab-pane>

				<el-tab-pane label="能源" name="seven">
					<el-checkbox v-for="(item,index) in energyList" :key="index" :label="item.id"
						@change="change($event,item.id)" v-model="item.isSelect">{{item.energyName}}（{{item.unit}}）
					</el-checkbox>
					<div class="mt20 textCenter">
						<!-- <el-button type="primary">保存</el-button> -->
					</div>
				</el-tab-pane>

				<el-tab-pane label="用电监控" name="eight">
					<el-form ref="form4" :model="ydjkParams" label-width="85px" label-position="left">
						<div class="displayFlexBet">
							<el-form-item label="设备DCS" prop="dcsMn" class="mr10">
								<el-input v-model="ydjkParams.dcsMn" @change="getDscRunList" @blur="getDscRunList"></el-input>
							</el-form-item>
							<el-form-item label="开关DCS" prop="dcsRun" class="mr10">
								<el-select v-model="ydjkParams.dcsRun" filterable>
									<el-option :label="item1.name" :value="item1.code" v-for="(item1,index1) in dcsRunList">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="开关标准值" prop="dcsRunStd" class="mr10">
								<el-input v-model="ydjkParams.dcsRunStd" type="number"></el-input>
							</el-form-item>
						</div>

					</el-form>
					<div class="mt20 textCenter">
						<el-button type="primary" @click="saveYgjk">保存</el-button>
					</div>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>

		<el-dialog v-if="visible2" :visible.sync="visible2" top="2%" title="新增产品信息" :modal="false" width="40%"
			append-to-body>
			<el-form ref="form2" :model="production" :rules="formRules2" label-width="100px" label-position="left">
				<el-form-item label="产品" prop="productId">
					<el-select v-model="production.productId" filterable placeholder="名称" style="width: 100%;">
						<el-option v-for="item in productChooseList" :key="item.id" :label="item.productName"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>

				<div class="displayFlex" v-for="(item,index) in production.relationList" :key="index" style="width: 100%;">
					<el-form-item label="原辅料" prop="pollutionId">
						<el-select v-model="item.materialId" filterable placeholder="原辅料" style="width: 100%;">
							<el-option v-for="item in materialChooseList" :key="item.id" :label="item.materialName"
								:value="item.id">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="单位产品用量" prop="percent" style="margin-left: 10px;">
						<el-input v-model="item.ratio" type="number" style="width: 100%;"></el-input>
					</el-form-item>

					<i style="color: #F56C6C;margin-bottom: 15px;font-weight: bold;margin-left: 20px;" class="el-icon-delete"
						@click="production.relationList.splice(index,1)"></i>
				</div>
				<div style="margin-bottom: 10px;">
					<el-button @click="production.relationList.push({'materialId':'','ratio':0})" size="small"
						type="primary">
						+ 添加原辅料
					</el-button>
				</div>

				<div class="displayFlex" v-for="(item,index) in production.semiProductRelationList" :key="index"
					style="width: 100%;">
					<el-form-item label="中间产品" prop="semiProductId">
						<el-select v-model="item.semiProductId" filterable placeholder="中间产品" style="width: 100%;">
							<el-option v-for="item in semiProductChooseList" :key="item.id" :label="item.productName"
								:value="item.id">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="单位产品用量" prop="percent" style="margin-left: 10px;">
						<el-input v-model="item.ratio" type="number" style="width: 100%;"></el-input>
					</el-form-item>

					<i style="color: #F56C6C;margin-bottom: 15px;font-weight: bold;margin-left: 20px;" class="el-icon-delete"
						@click="production.semiProductRelationList.splice(index,1)"></i>
				</div>
				<div>
					<el-button @click="production.semiProductRelationList.push({'semiProductId':'','ratio':0})" size="small"
						type="primary">
						+ 添加中间产品
					</el-button>
				</div>


				<div style="text-align: center;margin-top: 50px;">
					<el-button type="primary" @click="saveProduction(1)">保存</el-button>
				</div>
			</el-form>
		</el-dialog>

		<el-dialog v-if="visible3" :visible.sync="visible3" top="2%" title="污染物信息" :modal="false" width="60%"
			append-to-body>
			<el-form ref="form3" :model="material" :rules="formRules3" label-width="100px" label-position="left">
				<el-form-item label="原辅料" prop="materialId">
					<el-select v-model="material.materialId" filterable placeholder="名称" style="width: 100%;">
						<el-option v-for="item in materialChooseList" :key="item.id" :label="item.materialName"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>

				<div class="displayFlex" v-for="(item,index) in material.pollutionList" :key="index" style="width: 100%;">
					<el-form-item label="污染物类型" prop="pollutionType">
						<el-select :value="pollutionParams.pollutionType" placeholder="请选择" style="width: 100%;"
							@change="changePollution($event,item)">
							<el-option label="废气" value="GAS_POLLUTION" />
							<el-option label="废水" value="WATER_POLLUTION" />
						</el-select>
					</el-form-item>

					<el-form-item label="污染物" prop="pollutionId" style="margin-left: 10px;">
						<el-select v-model="item.pollutionId" filterable placeholder="污染物" style="width: 100%;">
							<el-option v-for="item in pollutionChooseList" :key="item.id" :label="item.pollutionName"
								:value="item.id">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="单位排污量" prop="percent" style="margin-left: 10px;">
						<el-input v-model="item.qty" type="number" style="width: 100%;"></el-input>
					</el-form-item>

					<i style="color: #F56C6C;margin-bottom: 15px;font-weight: bold;margin-left: 20px;" class="el-icon-delete"
						@click="material.pollutionList.splice(index,1)"></i>
				</div>
				<div @click="material.pollutionList.push({'pollutionId':'','qty':0})" style="color: #3a3ef4">添加污染物</div>

				<div style="text-align: center;margin-top: 50px;">
					<el-button type="primary" @click="saveMaterial(1)">保存</el-button>
				</div>
			</el-form>
		</el-dialog>

	</div>
</template>

<script>
	import productionEquipment from "./components/productionEquipment"
	let that

	export default {
		components: {
			productionEquipment
		},
		data() {
			return {
				dataList: [],
				params: {
					ticketId: '',
				},
				visible1: false,
				visible2: false,
				visible3: false,
				activeName: 'one',
				form: {},
				parameter: {
					list: []
				},
				production: {
					productId: '',
					relationList: [],
					semiProductRelationList: [],
				},
				material: {
					materialId: '',
					pollutionList: []
				},
				formRules: {
					equipmentName: [{
						required: true,
						message: '生产设施设备名称',
						trigger: 'blur'
					}]
				},

				formRules2: {
					productId: [{
						required: true,
						message: '产品',
						trigger: 'blur'
					}],
				},

				formRules3: {
					materialId: [{
						required: true,
						message: '原辅料',
						trigger: 'blur'
					}],
				},

				pollutionParams: {
					pollutionType: "GAS_POLLUTION"
				},

				outletParams: {
					gasOutletIdList: [],
					waterOutletIdList: [],
					equipmentId: ''
				},

				ydjkParams: {
					id: '', // 原辅料id
					dcsMn: '',
					dcsRun: '',
					dcsRunStd: '',
				},

				unitList: [],
				productList: [], //已添加的产品列表
				materialList: [], //原辅料列表
				energyList: [],
				pollutionList: [],
				materialChooseList: [],
				pollutionChooseList: [],
				productChooseList: [],
				semiProductChooseList: [],
				pageIndex: 0,
				totalPage: 0,
				gasOutletList: [],
				waterOutletList: [],
				dcsRunList: [],
			}
		},

		mounted: function() {
			that = this
			that.params.ticketId = that.$store.state.token

			that.ajax({
				url: '/codeType/listCodeValue',
				data: {
					typeCode: 'UNIT_TYPE'
				},
				success: function(data) {
					if (data.status == 1) that.unitList = data.data;
				}
			});

			that.ajax({
				url: '/entProduct/getEntProductList',
				data: JSON.stringify({
					busiStatus: "IN_USE",
					productType: "SEMI_PRODUCT"
				}),
				contentType: 'application/json',
				success: function(data) {
					if (data.status == 1) that.semiProductChooseList = data.data;
				}
			});

			that.getDataList()
			that.getGasWaterOutletList()
		},

		methods: {

			saveYgjk() {
				this.$confirm('是否确定保存用电监控?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					that.ajax({
						url: 'productionEquipment/saveProductionEquipmentMn',
						data: JSON.stringify(that.ydjkParams),
						contentType: 'application/json',
						success: function(result) {
							if (result.data) {
								that.$message.success("保存成功")
							}
						},
					})
				})
			},

			getDscRunList() {
				// if (!that.form.dcsMn) return that.$message.error("请输入设备dcs")
				that.ajax({
					url: '/dcs/parameter/list',
					data: {
						mn: that.ydjkParams.dcsMn,
					},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						that.dcsRunList = result.data
					},
				})
			},

			change(e, id) {
				that.ajax({
					url: '/productionEquipment/energy/updateEquipEnergy',
					data: JSON.stringify({
						energyId: id,
						equipmentId: that.form.id,
					}),
					contentType: 'application/json',
					success: function(data) {
						that.$message.success("保存成功！")
					}
				});
			},

			saveOutLetParams() {
				that.outletParams.equipmentId = that.form.id
				that.ajax({
					url: '/productionEquipment/outlet/save',
					data: JSON.stringify(that.outletParams),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							that.$message.success("保存成功！")
						}
					},
				})
			},

			changePollution(value, item) {
				that.pollutionParams.pollutionType = value
				if (value != that.pollutionParams.pollutionType) {
					item.pollutionId = ''
				}
				that.getEntPollutionList()
			},

			//删除生成设施
			deleteProductionEquipmentBase() {
				this.$confirm('是否确定删除此生产设施?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					that.ajax({
						url: '/productionEquipment/deleteProductionEquipmentBase?ticketId=' +
							that.params.ticketId,
						data: {
							equipmentId: that.form.id
						},
						contentType: 'application/x-www-form-urlencoded',
						success: function(result) {
							if (result.data) {
								that.visible1 = false
								that.getDataList()
							}
						},
					})
				})
			},

			getGasWaterOutletList() {
				that.ajax({
					url: '/productionEquipment/outlet/getGasOutletList?ticketId=' +
						that.params.ticketId,
					data: {},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						if (result.data) {
							that.gasOutletList = result.data
						}
					},
				})

				that.ajax({
					url: '/productionEquipment/outlet/getWaterOutletList?ticketId=' +
						that.params.ticketId,
					data: {},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						if (result.data) {
							that.waterOutletList = result.data
						}
					},
				})
			},

			//编辑
			editThis(item) {
				item.isEdit = true
				that.form = item
				that.productList = item.productList
				that.parameter.list = item.parameterList
				that.materialList = item.materialList
				that.pollutionList = item.pollutionList
				that.energyList = item.energyList
				if (item.gasOutletIdList) that.outletParams.gasOutletIdList = item.gasOutletIdList
				if (item.waterOutletIdList) that.outletParams.waterOutletIdList = item.waterOutletIdList
				that.ydjkParams = {
					dcsMn: item.dcsMn,
					dcsRun: item.dcsRun,
					dcsRunStd: item.dcsRunStd,
					id: item.id
				}
				that.getDscRunList()
				that.visible1 = true
			},

			load() {
				if (that.totalPage >= that.pageIndex) return false
				that.pageIndex += 1
				that.getDataList()
			},

			addMaterial(item) {
				if (!that.form.id) {
					return that.$message({
						message: '请先填写基本设施信息',
						type: 'error'
					});
				}
				//console.log(item)
				if (item) that.material = item
				else {
					that.material = {
						materialId: '',
						pollutionList: []
					}
				}

				that.visible3 = true
				that.material.equipmentId = that.form.id

				that.ajax({
					url: '/entProductMaterial/getEntProductMaterialList',
					data: JSON.stringify({
						materialTypeList: ['RAW_MATERIAL', 'SUBSIDIARY_MATERIAL']
					}),
					contentType: 'application/json',
					success: function(result) {
						that.materialChooseList = result.data
					},
				})

				that.getEntPollutionList()
			},

			getEntPollutionList() {
				that.ajax({
					url: '/entPollution/getEntPollutionList',
					data: JSON.stringify(that.pollutionParams),
					contentType: 'application/json',
					success: function(result) {
						that.pollutionChooseList = result.data
					},
				})
			},

			//保存原辅料
			saveMaterial() {
				that.ajax({
					url: 'productionEquipment/saveOrUpdateProductionEquipmentRawMaterial',
					data: JSON.stringify(that.material),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							that.getProductionEquipmentBaseModelById()
							that.visible3 = false
							return that.$message({
								message: '保存成功！',
								type: 'success'
							});
						}
					},
				})
			},

			//删除原辅料
			deleteMaterial(item) {
				this.$confirm('是否确定删除此原辅料?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					that.ajax({
						url: '/productionEquipment/deleteProductionEquipmentRawMaterial?ticketId=' +
							that.params.ticketId,
						data: {
							equipmentMaterialId: item.id
						},
						contentType: 'application/x-www-form-urlencoded',
						success: function(result) {
							if (result.data) {
								that.getProductionEquipmentBaseModelById()
							}
						},
					})
				})
			},

			addProduction(production) {
				if (!that.form.id) {
					return that.$message({
						message: '请先填写基本设施信息',
						type: 'error'
					});
				}
				if (production) that.production = production
				else {
					that.production = {
						productId: '',
						relationList: [],
						semiProductRelationList: []
					}
				}
				that.visible2 = true
				that.production.equipmentId = that.form.id

				that.ajax({
					url: '/entProductMaterial/getEntProductMaterialList',
					data: JSON.stringify({
						materialTypeList: ['RAW_MATERIAL', 'SUBSIDIARY_MATERIAL']
					}),
					contentType: 'application/json',
					success: function(result) {
						that.materialChooseList = result.data
					},
				})


				that.ajax({
					url: '/entProduct/getEntProductList',
					data: JSON.stringify({}),
					contentType: 'application/json',
					success: function(result) {
						that.productChooseList = result.data
					},
				})
			},

			//删除产品
			deleteProduction(item) {
				this.$confirm('是否确定删除此产品?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					that.ajax({
						url: '/productionEquipment/deleteProductionEquipmentProduct?ticketId=' +
							that.params.ticketId,
						data: {
							equipmentProductId: item.id
						},
						contentType: 'application/x-www-form-urlencoded',
						success: function(result) {
							if (result.data) {
								that.getProductionEquipmentBaseModelById()
							}
						},
					})
				})
			},

			//保存产品
			saveProduction() {
				this.$refs['form2'].validate(function(valid) {
					if (valid) {
						that.ajax({
							url: '/productionEquipment/saveOrUpdateProductionEquipmentProduct?ticketId=' +
								that.params.ticketId,
							data: JSON.stringify(Object.assign({
								ticketId: that.params.ticketId,
							}, that.production)),
							contentType: 'application/json',
							success: function(result) {
								if (result.data) {
									that.getProductionEquipmentBaseModelById()
									that.visible2 = false
									return that.$message({
										message: '保存成功！',
										type: 'success'
									});
								}
							},
						})
					}
				})
			},

			//获取基本信息
			getProductionEquipmentBaseModelById() {
				that.ajax({
					url: '/productionEquipment/getProductionEquipmentBaseModelById?ticketId=' +
						that.params.ticketId,
					data: {
						equipmentId: that.form.id
					},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						if (result.data) {
							that.productList = result.data.productList
							that.materialList = result.data.materialList
							that.pollutionList = result.data.pollutionList
						}
					},
				})
			},

			handleClick(tab, event) {
				if (tab.name != "one") {
					if (!that.form.id) {
						that.activeName = "one"
						return that.$message({
							message: '请先完善设施信息',
							type: 'warning'
						});
					}
				}
			},

			addInfo() {

			},

			saveInfo(step) {
				this.$refs['form'].validate(function(valid) {
					if (valid) {
						that.ajax({
							url: '/productionEquipment/saveOrUpdateProductionEquipmentBase?ticketId=' +
								that.params.ticketId,
							data: JSON.stringify(Object.assign({
								ticketId: that.params.ticketId,
							}, that.form)),
							contentType: 'application/json',
							success: function(result) {
								if (result.data){
									that.form.id = result.data
									that.ydjkParams.id = result.data
								} 
								if (step == 2) that.activeName = "two"
								return that.$message({
									message: '保存成功！',
									type: 'success'
								});
							},
						})
					}
				})
			},

			getDataList(isLoading = true) {
				that.ajax({
					url: '/productionEquipment/pageProductionEquipmentBase?pageIndex=' + that.pageIndex +
						'&pageSize=10&ticketId=' + that.params.ticketId,
					data: JSON.stringify({
						ticketId: that.params.ticketId,
					}),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							that.dataList[that.pageIndex] = result.data.records
							that.totalPage = result.data.total
							that.$forceUpdate()
							console.log(that.dataList)
						}
					},
				}, isLoading)
			},


		}
	}
</script>


<style scoped>
	.display_Flex_Bet {
		display: flex;
		justify-content: space-between;
	}
</style>